/*
 * SessionManager.java
 *
 * Created on April 12, 2001, 1:13 PM
 */

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/


package org.marketlive.biz.session.context;

import java.util.List;

import org.marketlive.biz.account.IAccountManager;
import org.marketlive.entity.account.ICustomerHome;

import javax.servlet.http.HttpServletRequest;


/**
 * Manages a customer's session information.
 * <br>
 * The intent of the CommerceSession is to contain all the session context
 * associated with a particular customer session on the site, including
 * the Customer, Order, Digital Coupons, etc.
 * It also provides access to the SessionLogger.
 *
 * To get the CommerceSessionManager, (and then the CommerceSession),
 * go throw the DefaultProxy as follows:
 * <pre>
 *   ICommerceSessionManager sessionManager =
 *     (ICommerceSessionManager) com.mmlive.block.proxy.DefaultProxy.Get().getComponent("session.context.manager");
 *   ICommerceSession commerceSession =
 *     sessionManager.getCommerceSession( request, response );
 * </pre>
 *
 * At the end of the JSP page you must release the session as follows:
 * <pre>
 *   sessionManager.releaseCommerceSession( commerceSession );
 * </pre>
 *
 * @author  Huw
 * @version
 */
public interface ICommerceSessionManager {

    /**
     * Constant representing all source codes.
     * Used when determining whether to store first, last or all source codes on a basket or an order.
     */
    final int SOURCE_CODE_ALL = 0;

    /**
     * Constant representing the first source code in the basket or commerce session.
     * Used when determining whether to store first, last or all source codes on a basket or an order.
     */
    final int SOURCE_CODE_FIRST = 1;

    /**
     * Constant representing the last source code in the basket or commerce session.
     * Used when determining whether to store first, last or all source codes on a basket or an order.
     */
    final int SOURCE_CODE_LAST = 2;

    /**
    * Returns Instance of AccountManager.
    * @return IAccountManager
    */
    IAccountManager getAccountManager();

    /**
     * The time in days a customer should be remembered.
     * Web apps will likely use a cookie to implement this.
     *
     * @return days. duration to remember the customer in days.
     */
    int getCustomerDuration();

    /**
     * Creates a new CommerceSession
     */
    ICommerceSession createSession(String customerId, String basketId);

    /**
     * Creates a new basket for the current customer.  Any existing basket is
     * unaffected.
     *
     * @param session
     */
    void startNewBasket(ICommerceSession session);


    /**
     * This is called at the start of an HTTP Request by the <code>CommerceSessionFilter</code>.
     *
     * @param session an <code>ICommerceSession</code> object.
     */
    void startRequest(ICommerceSession session);

    /**
     *  Runs all final processes registered for a commerce session.
     *  Called when a commerce session times out or its instance is
     *  about to be disroyed by the garbage collector.
     *
     * @param session the session to finalize
     * @deprecated As of version 5.3, <code>ICommerceSession</code> cannot be finalized or expired.
     */
    void finalizeCommerceSession( ICommerceSession session ) throws Exception;


    ICustomerHome getCustomerHome();

    void setCurrentRequest(HttpServletRequest httpRequest, ICommerceSession commerceSession);

    /**
	 * Returns the list of create session extensions.
	 *
	 * @return a list of <code>ICreateSessionExtension</code> objects.
	 */
	List getCreateSessionExtensions();

    /**
	 * Returns the list of start request extensions.
	 *
	 * @return a list of <code>IStartRequestExtension</code> objects.
	 */
	List getStartRequestExtensions();

    /**
	 * Returns the list of end request extensions.
	 *
	 * @return a list of <code>IEndRequestExtension</code> objects.
	 */
	List getEndRequestExtensions();

    /**
     * Returns the login extension list associated with this CommerceSessionManager.
     *
     * @return a list of <code>ILoginExtension</code> objects.
     */
	List getLoginExtensions();

    /**
     * Returns the logout extension list associated with this CommerceSessionManager.
     *
     * @return a list of <code>ILogoutExtension</code> objects.
     */
	List getLogoutExtensions();

    /**
     * Returns the register customer extension list associated with this CommerceSessionManager.
     *
     * @return a list of <code>IRegisterCustomerExtension</code> objects.
     */
	List getRegisterCustomerExtensions();

}

